﻿
$(function uploadFile(){
    $('#uploadFile_md').click(function () {
        window.open('/markdown/uploadFile/', 'UploadImage',
        "top=450,left=600,height=330,width=800,status=yes,toolbar=no,menubar=no,location=0,channelmode=0")
    })
});

$(function saveMDText(){
    $('#saveFile_md').click(function (){
        var op_value = document.getElementById("type_op").value;
        var tarfile = document.getElementById("files").value;
        var md_content = document.getElementById("content_md").value;
        var cur_editors = document.getElementById("cur_editors").value;
        console.log(cur_editors);
        $.ajax({
            url:  '/markdown/modify_markdown/',
            type: "post",
            data: {
                filepath : tarfile,
                option: op_value,
                cur_editors: cur_editors,
                content_md: md_content
            },
            dataType:"json",
            success: function (data) {
                alert(data.res);
            }
        });
    })
});

$(function getSelectValue() {
    $("#type_op").change(function act(){
        var flag = document.getElementsByName("flag")[0].checked;
        console.log("get flag,", flag)
        var op_value = document.getElementById("type_op").value;
        console.log("get value,", op_value)
        $.ajax({
                url:  '/markdown/get_filelist/',
                data: { flag: flag, option_type : op_value},
                type: "POST",
                dataType: "json",
                success: function (data) {
                    //console.log("response data: ",data)
                    $("#files").empty();
                    $.each (data.filelist, function(i, item){
                        $("#files").append("<option value=" + item + ">" + item + "</option>");  //添加一项option
                    })
                }
            });
    })
    });

$(function getCheckValue() {
    $("#flag").click(function actTwo(){
        var flag = document.getElementsByName("flag")[0];
        console.log("get flag,", flag.checked)
        var op_value = document.getElementById("type_op").value;
        console.log("get value,", op_value)
        $.ajax({
                url:  '/markdown/get_filelist/',
                type: "POST",
                data: {
                    flag: flag.checked,
                    option_type : op_value
                },
                dataType:"json",
                success: function (data) {
                    console.log("response data: ",data)
                    $("#files").empty();
                    $.each (data, function(i, item){
                        $("#files").append("<option value=" + item + ">" + item + "</option>");  //添加一项option
                    })
                }
            });
    })
});

$(function getChangeDirList() {
    $("#space_key").change(function getDirList(){
        var op_value = document.getElementById("space_key").value;
        console.log("get value,", op_value)
        $.ajax({
                url:  '/markdown/getDirList/',
                type: "GET",
                data: {space: op_value},
                dataType:"html",
                success: function (data) {
                    // console.log("response data: ",data)
                    $("#left_tbody").empty();
                    $("#left_tbody").html(data);
                }
            });
    })
});

$(function display_list() {
    $('#click_list').click(function () {
        var curValue = "none";
        var toc = document.getElementById("toc");
        var shopping = document.getElementById("toc_link");
        var content = document.querySelector(".editormd-markdown-toc");
        curValue = shopping.style.display;
        if(curValue == "none"){
            toc.setAttribute("style","height: 920px");
            shopping.setAttribute("style","display:block");
            document.getElementById("doc_toc").innerHTML = content.innerHTML;
        }else {
            toc.setAttribute("style","height: 80px");
            shopping.setAttribute("style","display:none");
        };
        })
})